package com.itheima_15;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeSet;

public class PokerDemo02 {
    public static void main(String[] args) {
        // 键是编号，值是牌
        HashMap<Integer, String> map = new HashMap<Integer, String>();

        // 编号
        ArrayList<Integer> array = new ArrayList<Integer>();

        // 定义花色
        String[] colors = {"♦️", "♣️", "♥️", "♠️"};
        // 定义数字
        String[] numbers = {"3", "4", "5", "6" ,"7", "8", "9", "10", "J", "Q", "K", "A", "2"};

        // index
        int index = 0;
        for (String color : colors) {
            for (String number : numbers) {
              map.put(index, color+number);
              array.add(index);
              index++;
            }
        }
        map.put(index, "小王");
        array.add(index);
        index++;
        map.put(index, "大王");
        array.add(index);

        // 洗牌
        Collections.shuffle(array);

        // 玩家
        TreeSet<Integer> zsSet = new TreeSet<Integer>();
        TreeSet<Integer> lsSet = new TreeSet<Integer>();
        TreeSet<Integer> wwSet = new TreeSet<Integer>();
        TreeSet<Integer> dpSet = new TreeSet<Integer>();

        // 发牌
        for (int i = 0; i < array.size(); i++) {
            int x = array.get(i);

            if (i >= array.size() - 3) {
                dpSet.add(x);
            } else if (i % 3 == 0) {
                zsSet.add(x);
            } else if (i % 3 == 1) {
                lsSet.add(x);
            } else if (i % 3 == 2) {
                wwSet.add(x);
            }
        }

        // 看牌
        lookPoker("张三",zsSet,map);
        lookPoker("李四",lsSet,map);
        lookPoker("王武",wwSet,map);
        lookPoker("底牌",dpSet,map);

    }

    public static void lookPoker(String name, TreeSet<Integer> treeSet, HashMap<Integer, String> map) {
        System.out.print(name + "的牌是：");
        for (Integer i : treeSet) {
            String s = map.get(i);
            System.out.print(s + "");
        }
        System.out.println();
    }
}
